#include "NStatusWindow.h"
#include "../../../Util/MyStrUtil.h"
#include <cstring>
#include <string>

NStatusWindow::NStatusWindow() : NWindow(80, LINES, 0, 0, true)
{
    printString(2, 2, "Environment: ");
    getyx(window, environment_p.y, environment_p.x);
    
    printString(2, 4, "Crossover method: ");
    getyx(window, crossover_p.y, crossover_p.x);
    
    printString(2, 6, "Solution structure: ");
    getyx(window, solution_p.y, solution_p.x);
    
    printString(2, 8, "Time remaining: ");
    getyx(window, time_p.y, time_p.x);
    
    printString(2, 10, "Generation count: ");
    getyx(window, generations_p.y, generations_p.x);
    
    printString(2, 12, "Top fitness: ");
    getyx(window, topFitness_p.y, topFitness_p.x);
    
    printString(2, 14, "Average fitness: ");
    getyx(window, avgFitness_p.y, avgFitness_p.x);
}

void NStatusWindow::setEnvironment(string newEnvironment)
{
    clearString(environment_p, environment.size());
    environment = newEnvironment;
    printString(environment_p, environment.c_str());
}

void NStatusWindow::setCrossover(string newCrossover)
{
    clearString(crossover_p, crossover.size());
    crossover = newCrossover;
    printString(crossover_p, crossover.c_str());
}

void NStatusWindow::setSolution(string newSolution)
{
    clearString(solution_p, solution.size());
    solution = newSolution;
    printString(solution_p, solution.c_str());
}

void NStatusWindow::setTime(int newTime)
{
    clearString(time_p, time.size());
    time = myNtoStr<int>(newTime);
    printString(time_p, time.c_str());
}

void NStatusWindow::setGenerations(int newGenerations)
{
    clearString(generations_p, generations.size());
    generations = myNtoStr<int>(newGenerations);
    printString(generations_p, generations.c_str());
}

void NStatusWindow::setTopFitness(double newTopFitness)
{
    clearString(topFitness_p, topFitness.size());
    topFitness = myNtoStr<double>(newTopFitness);
    printString(topFitness_p, topFitness.c_str());
}

void NStatusWindow::setAvgFitness(double newAvgFitness)
{
    clearString(avgFitness_p, avgFitness.size());
    avgFitness = myNtoStr<double>(newAvgFitness);
    printString(avgFitness_p, avgFitness.c_str());
}

void NStatusWindow::clearString(Point string_p, unsigned int strLength)
{
    printChar(string_p, ' ');
    for (unsigned int i = 1; i < strLength; ++i)
        printChar(' ');
}

NStatusWindow::~NStatusWindow()
{
}
